import modelExtend from '@/utils/modelExtend';
import HttpModel from './http';
import {doPostToObj, doPostParam} from '@/services/http'

let warningRecord = {
  namespace: 'warningRecord',
  state: {
    loading: true,
    detailsLoading: true,
    recordList: [],
    riskResultList: [],
    recordDetail: {},
    pagination: {
      current: 1,
      pageSize: 10,
      totle: 0
    }
  },
  effects: {
    //分页查询风控预警记录列表
    *queryRecordList ({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: { loading: true },
      })
      const response = yield call(doPostToObj, payload)
      yield put({
        type: 'save',
        payload: {
          loading: false,
          recordList: response.data?.rows,
          pagination: response.data?.pagination
        },
      })
      if (callback) callback(response);
      return response;
    },
    //预警记录详情
    *recordDetail ({ payload, callback }, { call, put }) {
      const response = yield call(doPostParam, payload)
      yield put({
        type: 'save',
        payload: { detailsLoading: true },
      })
      yield put({
        type: 'save',
        payload: { recordDetail: response.data },
      })
      yield put({
        type: 'save',
        payload: { detailsLoading: false },
      })
      if (callback) callback(response)
    },
    //风控预警记录执行措施记录列表
    *riskResultList ({ payload, callback }, { call, put }) {
      yield put({
        type: 'save',
        payload: { loading: true },
      })
      const response = yield call(doPostToObj, payload)
      yield put({
        type: 'save',
        payload: {
          loading: false,
          riskResultList: response.data?.rows,
          pagination: response.data?.pagination
        },
      })
      if (callback) callback(response)
    },
  },
  reducers: {
    save (state, action) {
      return {
        ...state,
        ...action.payload,
      }
    },
  },
}
warningRecord = modelExtend(HttpModel, warningRecord);
export default warningRecord;